package net.zjitc.login.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @Author Administrator
 * @Date 2020/5/29 10:52
 * 利用阿里巴巴Druid数据库连接池技术
 **/
public class JDBCUtils {
    private static DataSource ds;
    static {
        /* 加载配置文件进内存
        *  使用Druid初始化/实例化ds*/
        try {
            Properties pro=new Properties();
            pro.load(JDBCUtils.class.getClassLoader().getResourceAsStream("druid.properties"));
            ds= DruidDataSourceFactory.createDataSource(pro);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static DataSource getDataSource(){
        return ds;
    }

    public static Connection getConnection() throws SQLException {
        return ds.getConnection();
    }

    /* 释放资源close()*/
}
